import { useIntersectionObserver } from '@vueuse/core'

export default {
  install(app) {
    // 配置此应用
    // 自定义全局指令
    app.directive('lazy', {
      mounted(el, binding) {
        const { stop } = useIntersectionObserver(el, ([{ isIntersecting }]) => {
          if (isIntersecting) {
            el.src = binding.value
            stop()
          }
        })
      },
    })
  },
}
